/******************************************************************
 * Created by: DO HOANG HAI                                       
 * Date of Creation: 25/Dec/2007
 * Date of last modification: 8/Jan/2008
 *                                                                
 * Description: writing a list of Bibtex strings into a pdf file.
 ******************************************************************/


using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text;

namespace Pbdms.PDFMaker
{
    /// <summary>
    /// This class provides service to create a pdf file and write a list of Bibtex strings into the file
    /// </summary>
    public class BibTexWriter
    {
        ArrayList arlBibtex = new ArrayList();
        /// <summary>
        /// create an instance
        /// </summary>
        /// <param name="arlOfBibTexes"></param>
        public BibTexWriter(ArrayList arlOfBibTexes)
        {
            arlBibtex = arlOfBibTexes;
        }
        /// <summary>
        /// create the pdf document and write the list of bibtexes
        /// </summary>
        /// <param name="filePath"></param>
        public void getPDFDocument(String filePath)
        {
            Document doc = new Document();
            
            try
            {
                //create a pdf file
                PdfWriter.GetInstance(doc, new System.IO.FileStream(filePath, System.IO.FileMode.Create));
                doc.Open();
                
                int i = 1;
                foreach (object obj in arlBibtex)
                {
                    String bibTex = (string)obj;
                    //write bibTex
                    Paragraph pr = new Paragraph(i++ + ". "+bibTex, new Font(iTextSharp.text.Font.HELVETICA, 13, iTextSharp.text.Font.NORMAL, Color.BLACK));
                    doc.Add(pr);
                }                
            }
            catch
            {
                Common.Global.showMsgOneButton("Unsuccessful in writing pdf file, an unexpected error has occur, please try again", 'C');
            }
            finally
            {
                doc.Close();
            }
        }
    }
}
